/*
 * MIT License
 *
 * Copyright (c) 2024 org.zzz (https://gitee.com/frostforest)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package org.zzz.pcdc;

import java.sql.SQLException;
import java.time.LocalDateTime;

class PcdcProgress {
    // 表名常量
    public static final String TABLE_NAME_PREFIX = "zzz_pcdc_progress_";

    // 列名常量
    public static final String COL_ID = "id";
    public static final String COL_PROGRESS_DATETIME = "progress_datetime";
    public static final String COL_PROGRESS_ID = "progress_id";
    public static final String COL_UPPER_BOUNDARY = "upper_boundary";
    public static final String COL_PROCESSED_QTY = "processed_qty";
    public static final String COL_IS_COMPLETE = "is_complete";
    public static final String COL_ERROR_COUNTER = "error_counter";
    public static final String COL_CREATED_AT = "created_at";
    public static final String COL_UPDATED_AT = "updated_at";
    public static final String COL_LOCK_EXPIRE_TIME = "lock_expire_time";
    public static final String COL_WORKER_ID = "worker_id";

    // 实体字段
    private Integer id;
    private LocalDateTime progressDatetime;
    private Long progressId;
    private LocalDateTime upperBoundary;
    private Integer processedQty;
    private Boolean isComplete;
    private Short errorCounter;
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
    private LocalDateTime lockedUntil;
    private Integer workerId;

    public PcdcProgress() {

    }

    public static PcdcProgress from(java.sql.ResultSet rs) throws SQLException {
        PcdcProgress pcdcProgress = new PcdcProgress();
        pcdcProgress.setId(rs.getInt(COL_ID));
        pcdcProgress.setProgressDatetime(rs.getObject(COL_PROGRESS_DATETIME, LocalDateTime.class));
        pcdcProgress.setProgressId(rs.getLong(COL_PROGRESS_ID));
        pcdcProgress.setUpperBoundary(rs.getObject(COL_UPPER_BOUNDARY, LocalDateTime.class));
        pcdcProgress.setProcessedQty(rs.getInt(COL_PROCESSED_QTY));
        pcdcProgress.setIsComplete(rs.getBoolean(COL_IS_COMPLETE));
        pcdcProgress.setErrorCounter(rs.getShort(COL_ERROR_COUNTER));
        pcdcProgress.setCreatedAt(rs.getObject(COL_CREATED_AT, LocalDateTime.class));
        pcdcProgress.setUpdatedAt(rs.getObject(COL_UPDATED_AT, LocalDateTime.class));
        pcdcProgress.setLockedUntil(rs.getObject(COL_LOCK_EXPIRE_TIME, LocalDateTime.class));
        pcdcProgress.setWorkerId(rs.getInt(COL_WORKER_ID));
        return pcdcProgress;
    }

    // Getters and Setters
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public LocalDateTime getProgressDatetime() {
        return progressDatetime;
    }

    public void setProgressDatetime(LocalDateTime progressDatetime) {
        this.progressDatetime = progressDatetime;
    }

    public Long getProgressId() {
        return progressId;
    }

    public void setProgressId(Long progressId) {
        this.progressId = progressId;
    }

    public LocalDateTime getUpperBoundary() {
        return upperBoundary;
    }

    public void setUpperBoundary(LocalDateTime upperBoundary) {
        this.upperBoundary = upperBoundary;
    }

    public Integer getProcessedQty() {
        return processedQty;
    }

    public void setProcessedQty(Integer processedQty) {
        this.processedQty = processedQty;
    }

    public Boolean getIsComplete() {
        return isComplete;
    }

    public void setIsComplete(Boolean isComplete) {
        this.isComplete = isComplete;
    }

    public Short getErrorCounter() {
        return errorCounter;
    }

    public void setErrorCounter(Short errorCounter) {
        this.errorCounter = errorCounter;
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }

    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }

    public LocalDateTime getLockedUntil() {
        return lockedUntil;
    }

    public void setLockedUntil(LocalDateTime lockedUntil) {
        this.lockedUntil = lockedUntil;
    }

    public Integer getWorkerId() {
        return workerId;
    }

    public void setWorkerId(Integer workerId) {
        this.workerId = workerId;
    }
}